package com.huawei.cloud.phone.management.application.user;

import com.huawei.cloud.phone.management.application.user.dto.LoginInfoDTO;
import com.huawei.cloud.phone.management.application.user.dto.UserDTO;
import com.huawei.cloud.phone.management.domain.user.User;
import com.huawei.cloud.phone.management.domain.user.UserDomainService;
import lombok.AllArgsConstructor;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

@AllArgsConstructor
@Component
public class UserServiceImpl implements UserService {
    private final UserDomainService userDomainService;

    @Override
    public LoginInfoDTO register(@NonNull UserDTO userDTO) {
        userDomainService.register(userDTO.toUser());
        return this.login(userDTO);
    }

    @Override
    public LoginInfoDTO login(@NonNull UserDTO userDTO) {
        User user = userDomainService.login(userDTO.toUser());
        return new LoginInfoDTO(user);
    }

    @Override
    public void logout(@NonNull String sessionId) {
        userDomainService.logout(sessionId);
    }

    @Override
    public void forceLogout(@NonNull String username) {
        userDomainService.forceLogout(username);
    }
}
